package com.aaa.system.controller;

import com.aaa.entity.User;
import com.aaa.system.service.UserService;
import com.aaa.system.vo.UserVo;
import com.aaa.utils.JWTUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: aaa-education-parent
 * @description:
 * @author: 闫克起2
 * @create: 2024-03-06 11:32
 **/
@RestController
@RequestMapping("/system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("getName/{name}")
    public User getName(@PathVariable String name){
        return userService.queryByName(name);
    }

    @GetMapping("/info")
    public Result info(HttpServletRequest request){
        //从请求头获取token
        String token = request.getHeader("token");
        //解析请求头中用户名
        String name = JWTUtil.getName(token);
        User user = userService.queryByName(name);
        return new Result(2000,"查询成功",user);
    }

    //vo:表示view Object 视图对象  前端传递的查询参数的对象
    @PostMapping("/list/{current}/{pageSize}")
    public Result list(@PathVariable Integer current,@PathVariable Integer pageSize,@RequestBody UserVo userVo){
       Page<User> page=userService.selectPage(current,pageSize,userVo);
       return new Result(2000,"查询用户成功",page);

    }


}
//如果前端调用返回result结果